/**
 * 
 */
package fr.ece.ing4.si.mc.singleThreading;

import java.util.Random;

import fr.ece.ing4.si.mc.MonteCarlo.SingleMonteCarloController;

/**
 * @author Cesar Berezowski, Gaspard Peyrot
 * Class for single threading computation
 */
public class SingleMonteCarloMethod {
	
	/**
	 * Basic constructor
	 */
	public SingleMonteCarloMethod(){ }
	
	/**
	 * 
	 * @param z : flag for calling or putting
	 * @param s : underlying price
	 * @param x : strike price
	 * @param t : time left to maturity
	 * @param r : interest rate without risks
	 * @param dt : 
	 * @param drift : drift value
	 * @param vSqrdt : 
	 * @param nSteps : number of steps to do during calculations
	 * @param nSimulations : number of simulations to do
	 * @param c pointer on controller
	 * @return
	 */
	public double monteCarloStandardOption(int z, double s, double x, double r, double t, 
			double dt, double drift, double vSqrdt,int nSteps, int nSimulations, SingleMonteCarloController c) {
		
		double st;
		double sum = 0;
		
		Random rand = new Random(); 
		
		for(int i = 0; i < nSimulations; i++){
			st = s;
			for(int j = 0; j < nSteps; j++){
				st = st * Math.exp(drift + vSqrdt * rand.nextGaussian());
			}
			
			sum = sum + Math.max(z * (st - x), 0.0);
			System.out.println("Sum" + i + " = " + sum);
			c.updateProgress();
		}
		
		return (Math.exp(-r* t) * (sum / nSimulations));
	}
}
